package com.t.bricks.bussiness.db.dao.customergoldroll.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.t.bricks.bussiness.db.dao.customergoldroll.CustomerGoldRollDao;
import com.t.bricks.bussiness.db.entity.customergoldroll.CustomerGoldRoll;
import com.t.bricks.bussiness.db.mapper.customergoldroll.CustomerGoldRollMapper;
import com.t.bricks.model.Log;
import com.t.bricks.model.MsgEmity;

@Repository
public class CustomerGoldRollDaoImpl implements CustomerGoldRollDao<CustomerGoldRoll> {
	
	@Autowired
	private CustomerGoldRollMapper customerGoldRollMapper;
	
	/**
	 * 领取代金卷
	 * @param sGoldRollNo 代金卷号码
	 * @param sCustomerId 顾客账号
	 * @return
	 */
	@Override
	@Transactional
	public MsgEmity employ(String sGoldRollNo, String sCustomerId) {
		try {
			int i = customerGoldRollMapper.employ(sGoldRollNo, sCustomerId);
			if (i < 1) {
				Log.error("新增未能得到预期影响值(预期1):", i);
				return new MsgEmity(false, "新增数据失败！", 7001);
			}
		} catch (Exception e) {
			Log.error("新增时发生异常:", e.getMessage());
			return new MsgEmity(false, "新增失败！", 7002);
		}
		
		return new MsgEmity(true, "新增成功！", 7999);
	}

	/**
	 * 使用代金卷
	 * @param sGoldRollNo 代金卷号码
	 * @return
	 */
	@Override
	@Transactional
	public MsgEmity use(String uId) {
//		try {
//			int i = customerGoldRollMapper.changeState(uId, 2, 1, null);
//			if (i < 1) {
//				Log.error("新增未能得到预期影响值(预期1):", i);
//				return new MsgEmity(false, "新增数据失败！", 7001);
//			}
//		} catch (Exception e) {
//			Log.error("新增时发生异常:", e.getMessage());
//			return new MsgEmity(false, "新增失败！", 7002);
//		}
//		
//		
//		customerGoldRollMapper.changeState(uId, 2, 1, null);
		
		
		return null;
	}

}
